package cn.wizzer.app.web.modules.controllers.platform.user.account;

import cn.wizzer.app.user.modules.services.UserCashService;
import cn.wizzer.app.web.commons.ulog.annotation.SLog;
import cn.wizzer.app.web.commons.utils.StringUtil;
import cn.wizzer.framework.base.Result;
import com.alibaba.dubbo.config.annotation.Reference;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;

@IocBean
@At("/platform/user/account/cash")
public class CashController {
    private static final Log log = Logs.get();

    @Inject
    @Reference
    private UserCashService cashService;

    @At("")
    @Ok("beetl:/platform/user/account/cash/index.html")
    @RequiresPermissions("user.account.cash")
    public void index() {

    }

    @At("/add")
    @Ok("json")
    @RequiresPermissions("user.account.cash.add")
    @SLog(tag = "申请转出", msg = "申请为用户:${args[0]}转出:${args[1]}")
    public Object addDo(@Param("toUser") String toUser, @Param("amount") BigDecimal amount, HttpServletRequest req) {
        cashService.add(amount, toUser, StringUtil.getPlatformUid());
        return Result.success();
    }

    @At("/sure")
    @Ok("json")
    @RequiresPermissions("user.account.cash.sure")
    @SLog(tag = "确认转出", msg = "确认转发${args[0]}")
    public Object sure(@Param("id") String id, @Param("sure") Boolean sure, HttpServletRequest req) {
        cashService.sure(id, sure, StringUtil.getPlatformUid());
        return Result.success();
    }


    @At
    @Ok("json:full")
    @RequiresPermissions("user.account.cash")
    public Object data(@Param("searchName") String searchName, @Param("searchKeyword") String searchKeyword, @Param("pageNumber") int pageNumber, @Param("pageSize") int pageSize) {
        return Result.success().addData(cashService.listPage(searchKeyword,pageNumber, pageSize));
    }


}
